var speech:ISpeech;

Function LuaTTSSpeakText(l:lua_state):integer; cdecl;
var s:WideString;
begin
if lua_gettop(l) <> 1 then lual_error(l, 'tts.speakText expects 1 parameter (text).', []);
s := LuaToString(l, 1);
speech^.speakText(PWideChar(s));
result:=0;
end;
Function LuaIndexTTS(l:lua_state):integer; cdecl;
var s:string;
begin
 s := LuaToString(l, 2);
 result:=1;
 if s = 'rate' then lua_pushinteger(l, Speech^.getRate()) else
if s = 'volume' then lua_PushInteger(l, Speech^.GetVolume()) else
result := 0;
 end;
                        function LuaNewIndexTTS(l:lua_state):integer; cdecl;
var s:string;
                        begin
             result:=0;
             s := luaToString(l, 2);
             if s = 'rate' then speech^.setRate(Lua_ToInteger(l, 3)) else
             if s= 'volume' then speech^.setVolume(Lua_ToInteger(l, 3));
                        end;

 procedure RegisterSpeech;
begin
speech := Core_RequirePlugin(SpeechI.SpeechGUID);
LuaRegister(l, 'tts.speakText', LuaTTSSpeakText);
Lua_GetGlobal(l, 'tts');
lua_NewTable(l);
lua_PushCFunction(l, LuaIndexTTS);
lua_SetField(l, -2, '__index');
lua_PushCFunction(l, LuaNewIndexTTS);
lua_SetField(l, -2, '__newindex');
lua_setMetatable(l, -2);
end;